<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_business/model')->方法名();
*/
namespace jy_business;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function upimg($img=''){
		$setting=$this->plugin_setting('setting');
		$host = "https://bizlicense.market.alicloudapi.com";
		$path = "/rest/160601/ocr/ocr_business_license.json";
		$method = "POST";
		$appcode = $setting['AppCode'];
		if(!$appcode){
			exi('appcode不能为空','error');
		}
		$img=tomedia($img);
		$rurl = $host . $path;
		$extra=array(
				'Content-Type' => 'application/json',
				'Authorization'=> 'APPCODE '.$appcode
		);
		$post=array('image'=>$img);
		$post=ijson_encode($post);
		$result=cfc('http')->ihttp_request($rurl,$post,$extra);
		if(is_error($result)){			
			$message="访问失败, 错误: {$result['message']}";
			if($return_error){
				return error($message);
			}else{
				exi($message,'error');
			}
		}
		$data=preg_replace('/[\x00-\x1F]/','',$result['content']);
		$data=@json_decode($data,true);
		if($data['errcode']){
		}
		if($direct){
			return $result;
		}
		if(!is_array($data) || !$data){
			$message='访问接口错误，以下为原始数据：'.$result['content'];
			if($return_error){
				return error($message);
			}else{
				exi($message,'error');
			}
		}
		return $data;
	}
}
?>